	<?php $this->load->view('admin/partials/tournament_menu'); ?>
	<?php 
		$ci= &get_instance();
		$match_array = $ci->match_entity->getArrayListOfMatch($tournament_id);
		$TOURNAMENT = $ci->tournament_entity->init('id',$tournament_id);
		$match_status_array = matchStatusDataConfig();
		$bet_status_array = betStatusDataConfig();
		
	 
	?>
	
	<div class="clrboth"></div>
	
	<h3>Matches of Tournament &raquo; <?php echo $TOURNAMENT->getName();?></h3>
	<?php $buttons = array('buttons'=>array("Add#add_new_match({$tournament_id});") );?>
	<?php $this->load->view('admin/partials/buttons', $buttons ); ?>
	
	<div class="clrboth"></div>
	
	<table border="0" class="table-list">
		<thead>
			<tr>
				<th>Feed Info.</th>
				<th>Home</th>
				<th>Away</th>
				<th>Result</th>
				<th>Date/time</th>
				<th>Scoreboard</th>
				<th>Event</th>
				<th>Manual Event</th>
				<th>Bet status</th>
				<th>Status</th>
				<th>Match manage</th>
			</tr>
		</thead>
		
		<tbody>
			<?php $i=0; foreach( $match_array as $key=> $item ): ?>
			<?php 
				$MATCH = $ci->match_entity->init('id', $item->id);
				$HOME = clone_( $ci->team_entity->init('id',$MATCH->getHome()) );
				$AWAY = clone_($ci->team_entity->init('id',$MATCH->getAway()) );
				$i++;
			?>
			<tr id="match_id_<?php echo $item->id;?>">
				<td> 
					<?php if($MATCH->getFeedMatchId()):?>
						<?php 
							$type = $MATCH->getFeedType();
							$key = $MATCH->getFeedKey();
							$category_id = $MATCH->getFeedCategoryId();
							$match_id = $MATCH->getFeedMatchId();
						?>
						<a href="javascript:void(0);" onclick="return viewInning('<?php echo $type;?>','<?php echo $key;?>',<?php echo $category_id;?>,<?php echo $match_id;?>,<?php echo $i;?>);">Inning</a> <br/>
						<a href="javascript:void(0);" onclick="return viewComment('<?php echo $type;?>','<?php echo $key;?>',<?php echo $category_id;?>,<?php echo $match_id;?>,<?php echo $i;?>);">Commentaries</a> <br/>
						<a href="javascript:void(0);" onclick="return viewWicket('<?php echo $type;?>','<?php echo $key;?>',<?php echo $category_id;?>,<?php echo $match_id;?>,<?php echo $i;?>);">Wickets</a> <br/>
						<a href="javascript:void(0);" onclick="return viewLineup('<?php echo $type;?>','<?php echo $key;?>',<?php echo $category_id;?>,<?php echo $match_id;?>,<?php echo $i;?>);">Lineups</a> <br/>
						<a href="javascript:void(0);" onclick="return viewMatchInfo('<?php echo $type;?>','<?php echo $key;?>',<?php echo $category_id;?>,<?php echo $match_id;?>,<?php echo $i;?>);">Matchinfo</a> <br/>
						<?php echo loader_image("id=\"loader_image_$i\" class=\"hidden\"");?>
					<?php endif;?>
				</td>
				<td>
					<?php echo $MATCH->displayMatchInfo('home'); ?>
				</td>
				<td>
					<?php echo $MATCH->displayMatchInfo('away'); ?>
				</td>
				<td>
					<?php echo $MATCH->displayMatchInfo('closed'); ?>
				</td>
				<td>
				From <?php echo sysDateTimeFormat($MATCH->getStartTime(),DATE_FM); ?> <br/>
				To <?php echo sysDateTimeFormat($MATCH->getEndTime(),DATE_FM); ?>
				</td>
				<td>
					<?php if($MATCH->getFeedMatchId()):?>	
						<a href="javascript:void(0);" onclick="batsman_dialog(<?php echo $MATCH->getId();?>)" >Batsman</a>
						<br />
						<a href="javascript:void(0);" onclick="scorecard_dialog(<?php echo $MATCH->getId();?>)" >Scorescard</a>
					<?php endif;?>	
				</td>	
				<td>
					<?php 
					/*	echo form_dropdown( 'event',
											$options = array(
												'choose'=>"--Choose--",
												'add_category_event'=>"Add category event",
												'view_category_event'=>"View category event",
												'add_event'=>"Add event",
												'view_event'=>"View event"
											),
											$selected = array(),
											"id='event' onchange='function_of_event(this.value,{$MATCH->getId()},this);' class='no-uniform eventslb'"
										);
					*/					
					?>
					<a href="javascript:void(0);" onclick="view_event(<?php echo $MATCH->getId();?>)">
						View
					</a>
				</td>
				<td><a href="javascript:void(0);" onclick="view_manual_event(<?php echo $MATCH->getId();?>)">View</a></td>
				<td>
					<a href="javascript:void(0);" onclick="change_bet_status_match(<?php echo $MATCH->getId();?>)">
						<?php echo $bet_status_array[$MATCH->getBetEnable()];?>
					</a>
				</td>
				<td>
					<?php echo $match_status_array[$MATCH->getStatus()];?>
				</td>
				<td>
					<a href="javascript:void(0);" onclick="match_edit(<?php echo $MATCH->getId();?>, <?php echo $tournament_id;?>)"><?php echo lang('dataman.edit');?></a>
					<?php if( $MATCH->getStatus() == 'living' OR $MATCH->getStatus() == 'upcoming' ):?>
						&nbsp;|&nbsp;
						<a href="javascript:void(0);" onclick="match_cancel(<?php echo $MATCH->getId();?>, <?php echo $tournament_id;?>)" >Cancel</a>
					<?php endif;?>	
					<?php if(! $MATCH->isMatchFinished()):?>
						&nbsp;|&nbsp;
						<a href="javascript:void(0);" onclick="match_finish(<?php echo $MATCH->getId();?>, <?php echo $tournament_id;?>)" >Finish</a>
					<?php endif;?>	
					<?php if( $MATCH->getStatus() == 'living' OR $MATCH->getStatus() == 'closed' ):?>
						&nbsp;|&nbsp;
						<a href="javascript:void(0);" onclick="match_show_feature(<?php echo $MATCH->getId();?>)" >
							<?php 
								if($MATCH->getShowFeature() == 1){
									echo 'Showed at scoreboard';
								}else{
									echo 'Not show at scoreboard';
								}
							?>
						</a>
					<?php endif;?>	
					<?php if( $MATCH->getFeedMatchId()):?>
						&nbsp;|&nbsp;
						<a href="javascript:void(0);" onclick="remove_xml_match_update(<?php echo $MATCH->getId();?>)">Remove XML Feed Update</a>
					<?php endif;?>	
					<?php echo loader_image("id=\"loader_image_match_{$MATCH->getId()}\" class=\"hidden\"");?>
				</td>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>

<?php 
	if(isset($_GET['fmid'])):
?>	
	<script type="text/javascript">
		var FMID = <?php echo intval($_GET['fmid']);?>;
		jQuery(document).ready(function(){
			jQuery('#match_id_'+FMID).addClass('find');
		});
	</script>
<?php endif; ?>	
	
<script type="text/javascript">
	jQuery(document).ready(function(){
		
	});
	
	function remove_xml_match_update(match_id){
		jQuery("#loader_image_match_"+match_id).toggle();
		jQuery.post(BASE_URI+'admin/dataman/match/remove_xml_match_update',{match_id:match_id},function(res){
			reload();
		});
	}
	
	function score_item_delete(id,match_id){
		jQuery("#loader_image_"+id).show();
		jQuery.post(BASE_URI+'admin/dataman/match/score_item_delete',{id:id},function(res){
			scorecard_dialog(match_id);
		});
	}
	
	function score_item_edit(id,match_id){
		jQuery.post(BASE_URI+'admin/dataman/match/scorecard_add_item',{id:id,match_id:match_id},function(res){
			jQuery('#dialog2').html(res);
			jQuery('#dialog2').dialog(
				{
					 width: 550,
					 resizable: false,
					 height:200,
					 title: 'Scorecard Edit Item' 
				}
			);
		});
	}
	
	function do_save_scorecard(){
		jQuery('#loader_image').show();
		$json = jQuery("#scorecard_submit_item").serializeJSON();
	 
		jQuery.post(BASE_URI+'admin/dataman/match/scorecard_add_submit',{data:$json},function(res){
			scorecard_dialog($json.match_id);
			jQuery('#loader_image').hide();
			jQuery('#dialog2').dialog('close');
		});
	}
	
	function add_score_item(match_id){
		jQuery.post(BASE_URI+'admin/dataman/match/scorecard_add_item',{match_id:match_id},function(res){
			jQuery('#dialog2').html(res);
			jQuery('#dialog2').dialog(
				{
					 width: 550,
					 resizable: false,
					 height:200,
					 title: 'Scorecard Add Item' 
				}
			);
		});
	}
	
	function scorecard_dialog(match_id){
		jQuery.post(BASE_URI+'admin/dataman/match/scorecard_view',{match_id:match_id},function(res){
			jQuery('#dialog').html(res);
			jQuery('#dialog').dialog(
				{
					 width: 550,
					 resizable: false,
					 height:400,
					 title: 'Scorecard View' 
				}
			);
		});
	}
	
	function do_save_batsman(){
		jQuery('#loader_image').show();
		$json = jQuery("#batsman_submit").serializeJSON();
	 
		jQuery.post(BASE_URI+'admin/dataman/match/batsman_submit',{data:$json},function(res){
			jQuery('#loader_image').hide();
			alert(res);
		});
	}
	
	function batsman_dialog(match_id){
		jQuery.post(BASE_URI+'admin/dataman/match/batsman',{match_id:match_id},function(res){
			jQuery('#dialog').html(res);
			jQuery('#dialog').dialog(
				{
					 width: 550,
					 resizable: false,
					 height:400,
					 title: 'Batsman View' 
				}
			);
		});
	}
	
	function match_show_feature(match_id){
		jQuery('#loader_image_match_'+match_id).show();
		jQuery.post(BASE_URI+'admin/dataman/match/match_show_feature',{match_id:match_id},function(res){
			reload();
		});
	}
	
	function viewInning(type, key, category_id, match_id,i){
		jQuery('#loader_image_'+i).show();
		jQuery.post(BASE_URI+'admin/dataman/feed/viewInning',{type:type,key:key,category_id:category_id,match_id:match_id},function(res){
			jQuery('#loader_image_'+i).hide();
			jQuery('#dialog').html(res);
			jQuery('#dialog').dialog(
				{
					 width: 850,
					 resizable: false,
					 height:700,
					 title: 'Inning Information' 
				}
			);
		});
	}
	
	function viewComment(type, key, category_id, match_id,i){
		jQuery('#loader_image_'+i).show();
		jQuery.post(BASE_URI+'admin/dataman/feed/viewComment',{type:type,key:key,category_id:category_id,match_id:match_id},function(res){
			jQuery('#loader_image_'+i).hide();
			jQuery('#dialog').html(res);
			jQuery('#dialog').dialog(
				{
					 width: 850,
					 resizable: false,
					 height:700,
					 title: 'Comment Information' 
				}
			);
		});
	}
	
	function viewWicket(type, key, category_id, match_id,i){
		jQuery('#loader_image_'+i).show();
		jQuery.post(BASE_URI+'admin/dataman/feed/viewWicket',{type:type,key:key,category_id:category_id,match_id:match_id},function(res){
			jQuery('#loader_image_'+i).hide();
			jQuery('#dialog').html(res);
			jQuery('#dialog').dialog(
				{
					 width: 850,
					 resizable: false,
					 height:700,
					 title: 'Wickets Information' 
				}
			);
		});
	}
	
	function viewLineup(type, key, category_id, match_id,i){
		jQuery('#loader_image_'+i).show();
		jQuery.post(BASE_URI+'admin/dataman/feed/viewLineup',{type:type,key:key,category_id:category_id,match_id:match_id},function(res){
			jQuery('#loader_image_'+i).hide();
			jQuery('#dialog').html(res);
			jQuery('#dialog').dialog(
				{
					 width: 850,
					 resizable: false,
					 height:700,
					 title: 'Lineups Information' 
				}
			);
		});
	}
	
	function viewMatchInfo(type, key, category_id, match_id,i){
		jQuery('#loader_image_'+i).show();
		jQuery.post(BASE_URI+'admin/dataman/feed/viewMatchInfo',{type:type,key:key,category_id:category_id,match_id:match_id},function(res){
			jQuery('#loader_image_'+i).hide();
			jQuery('#dialog').html(res);
			jQuery('#dialog').dialog(
				{
					 width: 850,
					 resizable: false,
					 height:700,
					 title: 'Match Information' 
				}
			);
		});
	}

</script>
